#include "RingBuffer.hpp"
#include <unistd.h>
#include <cstdio>
#include<functional>
#include<ctime>

using namespace RingBufferModule;



void *Consumer(void* args)
{
    RingBuffer<int> *ring_buffer = static_cast<RingBuffer<int>*>(args);
    while(true)
    {
        int data;
        ring_buffer->Pop(&data);

        std::cout << "消费一个数据： " << data << std::endl;
    }
}

void *Productor(void* args)
{
    RingBuffer<int> *ring_buffer = static_cast<RingBuffer<int>*>(args);
    int data = 0;
    while(true)
    {
        ring_buffer->Equeue(data);
        std::cout << "生产一个数据： " << data << std::endl;
        data++;

    }
}


int main()
{
    
    pthread_t c,p;
    RingBuffer<int> *ring_buffer = new RingBuffer<int>(5);//创建共享资源-》临界
    //单生产单消费（多生产时只需要加线程就行）
    pthread_create(&c, nullptr,Consumer,ring_buffer);
    pthread_create(&p, nullptr,Productor,ring_buffer);


    pthread_join(c,nullptr);
    pthread_join(p,nullptr);

    delete ring_buffer;

    return 0;
}